﻿using System;


namespace IupNET
{
    public class Color
    {
        public readonly uint argb;
        private readonly bool nullcolor=false; //means empty/null/void color

        private Color(uint argb,bool nullcolor) {
            this.argb=argb;
            this.nullcolor=nullcolor;
        }

       
        public byte R
        {
            get
            {
                return (byte)((argb >> 16) & 255);
            }
        }

        public int G
        {
            get
            {
                return (byte)((argb >> 8) & 255);
            }
        }

        public int A
        {
            get
            {
                return (byte)((argb >> 24) & 255);
            }
        }

        public int B
        {
            get
            {
                return (byte)(argb & 255);
            }
        }

       

        public static Color FromARGB(byte a,byte r,byte g,byte b) {
            return new Color((uint)(a << 24) | (uint)(r << 16) | (uint)(g << 8) | (uint)b,false);
        }

        public static Color FromRGB(byte r, byte g, byte b)
        {
            return new Color((uint)(r << 16) | (uint)(g << 8) | (uint)b,false);
        }

        public int RGB
        {
            get
            {
                return (int)(argb & 0xffffff);
            }
        }

        public uint ARGB
        {
            get
            {
                return argb;
            }
        }

        public static bool operator ==(Color a, Color b)
        {
            if ((object)a == null)
                return (object)b == null;
            if ((object)b == null)
                return false;

            if (a.nullcolor != b.nullcolor) //one of the colors only are empty
                return false;
            if (a.nullcolor && b.nullcolor) //if booth are empty they equals, whatever color is...
                return true;

            return a.argb == b.argb;
        }

        public static bool operator !=(Color a, Color b)
        {
            return !(a == b);
        }


        public override int GetHashCode()
        {
          return argb.GetHashCode();
        }

        public override bool Equals(object obj)
        {
          return this == obj as Color;
        }

        public static readonly Color Red = new Color(0xff0000, false);
        public static readonly Color Green = new Color(0x00ff00, false);
        public static readonly Color Blue = new Color(0x0000ff, false);
        public static readonly Color Yellow = new Color(0xffff00, false);
        public static readonly Color Cyan = new Color(0x00ffff, false);
        public static readonly Color Magenta = new Color(0xff00ff, false);
        public static readonly Color White = new Color(0xffffff, false);
        public static readonly Color Black = new Color(0x000000, false);
        public static readonly Color Empty = new Color(0x000000, true);


    }
}
